package com.mlnx.work.controller;

import com.mlnx.common.entity.Response;
import com.mlnx.common.form.PageForm;
import com.mlnx.work.config.ControllerNames;
import com.mlnx.work.entity.ProjectArrange;
import com.mlnx.work.entity.ProjectDir;
import com.mlnx.work.entity.ProjectOverdue;
import com.mlnx.work.entity.Tag;
import com.mlnx.work.enums.ProjectStatusEnum;
import com.mlnx.work.enums.ResponseEnum;
import com.mlnx.work.exception.WorkServiceException;
import com.mlnx.work.pojo.form.ArrangeForm;
import com.mlnx.work.pojo.form.OverdueForm;
import com.mlnx.work.pojo.form.ProjectFilterForm;
import com.mlnx.work.pojo.form.ProjectForm;
import com.mlnx.work.service.*;
import com.mlnx.work.utils.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.BaseController;
import org.shan.spring.base.annotations.SysLog;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = ControllerNames.TagName + "接口", tags = {ControllerNames.TagName + "接口"})
@SysLog(title = ControllerNames.TagName)
@RestController
@RequestMapping("/tag")
public class TagController extends BaseController {
    @Autowired
    private TagService tagService;

    @ApiOperation("新增标签")
    @PostMapping("")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tagName", value = "标签名", required = true),
            @ApiImplicitParam(name = "creatorId", value = "创建者ID", required = true)
    })
    public Response addTag(@RequestParam String tagName, @RequestParam Integer creatorId) {
        Tag tag = new Tag();
        tag.setTagName(tagName);
        tag.setCreatorId(creatorId);
        tag.setCreateTime(System.currentTimeMillis());

        tagService.save(tag);
        return result(tag.getId());
    }

    @ApiOperation("获取所有标签")
    @GetMapping("")
    public Response tags() {
        return result(tagService.list());
    }
}
